<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html>
<head>
  <base href="/oa1/" />
  <title>修改信息</title>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <link href="static/bootstrap-3.3.5/css/bootstrap.css" rel="stylesheet">
  <link href="static/bootstrapvalidator/css/bootstrapValidator.css" rel="stylesheet">
  <link href="static/summernote/summernote.css" rel="stylesheet">
  <script src="static/jquery/jquery-1.10.2.min.js"></script>
  <script src="static/bootstrap-3.3.5/js/bootstrap.min.js"></script>
  <script src="static/bootstrapvalidator/js/bootstrapValidator.js"></script>
  <script src="static/summernote/summernote.js"></script>
  <script src="static/summernote/lang/summernote-zh-CN.js"></script>
</head>
<body>
<div class="panel panel-primary">
  <div class="panel-heading">
    <h4 class="panel-title">修改信息</h4>
  </div>

  <form action="xx/information/editInformation" enctype="multipart/form-data" id="myform" method="post" class="form-horizontal">
    <div class="panel-body">
      <div class="form-group col-md-12">
        <div class="col-md-6">
          <label for="title" class="col-md-4 control-label">信息标题</label>
          <div class="col-md-8">
            <input type="hidden" name="oid" value="${xxInformation.oid}">
            <input type="text" id="title" name="title" class="form-control" value="${xxInformation.title}">
          </div>
        </div>
        <div class="col-md-6">
          <label for="typeid" class="col-md-4 control-label">消息类别</label>
          <div class="col-md-8">
            <select id="typeid" name="typeid" class="form-control">
              <option value="">--请选择--</option>
              <option value="1" ${xxInformation.typeid == 1 ? 'selected' : ''}>公司新闻</option>
              <option value="2" ${xxInformation.typeid == 2 ? 'selected' : ''}>通知公告</option>
            </select>
          </div>
        </div>
      </div>

      <div class="form-group col-md-12">
        <div class="col-md-11 col-md-offset-1">
          <textarea id="summernote" class="summernote">${xxInformation.content}</textarea>
          <input type="hidden" id="content" name="content"/>
        </div>
      </div>

      <div class="form-group col-md-12">
        <div class="col-md-6">
          <label for="accpath" class="col-md-4 control-label">信息附件</label>
          <div class="col-md-8">
            <input type="file" id="accpath" name="accpath">
            <c:if test="${not empty xxInformation.file}">
              <p>当前附件：<a href="xx/information/downloadInfoFile?oid=${xxInformation.oid}">${xxInformation.file}</a></p>
            </c:if>
          </div>
        </div>
        <div class="col-md-6">
          <label for="closeDate" class="col-md-4 control-label">停止时间</label>
          <div class="col-md-8">
            <input type="date" id="closeDate" name="closeDate" class="form-control" value="${xxInformation.closeDate}">
          </div>
        </div>
      </div>

      <div class="form-group col-md-12">
        <div class="col-md-10 col-md-offset-2">
          <a href="javascript:history.back()" class="btn btn-info">返回</a>
          <button type="button" id="editInformationBtn" class="btn btn-success">确认修改</button>
          <button type="reset" id="resetbtn" class="btn btn-default">取消</button>
        </div>
      </div>
    </div>
  </form>
</div>

<script type="text/javascript">
  $(document).ready(function() {
    $('#summernote').summernote({
      lang: 'zh-CN',
      height: 200,
      callbacks: {
        onChange: function() {
          $("#content").val($(this).summernote('code'));
        }
      }
    });

    $("#myform").bootstrapValidator({
      feedbackIcons: {
        valid: 'glyphicon glyphicon-ok',
        invalid: 'glyphicon glyphicon-remove'
      },
      fields: {
        title: {
          validators: {
            notEmpty: {message: '标题不能为空'},
            stringLength: {min:1, max:50, message: '标题长度1-50位'}
          }
        },
        typeid: {
          validators: {
            notEmpty: {message: '请选择类别'}
          }
        }
      }
    });

    $("#editInformationBtn").click(function(){
      if($('#myform').data("bootstrapValidator").isValid()){
        if ($('#summernote').summernote('isEmpty')) {
          alert("请输入内容!");
          return;
        }
        $("#myform").submit();
      }
    });
  });
</script>
</body>
</html>